<?php
	$wpsj = array();
	header('Content-type:text/html;charset=utf-8');
	$link = mysqli_connect('localhost','root','root','sc');
	mysqli_select_db($link,'sc');
	mysqli_set_charset($link,'utf8');
	$zhi=$_GET["zhi"];
	$urse=$_GET["urse"];
	$pas=$_GET["pas"];
	if($zhi=='dl'){
		$sql="select pas from urse where name='".$urse."';";
		$zx=mysqli_query($link,$sql);
		while ($row = mysqli_fetch_assoc($zx)){
			$wpsj[]= $row;
		}
		if ($wpsj[0]['pas']=="") {
			$wpsj[]="用户名不存在,请重新登录";
			
		}
		else{
			if ($wpsj[0]['pas']==$pas && !$pas==null) {
				$wpsj=null;
				$wpsj[]="登录成功，即将跳转
				<script type='text/javascript'>
					setTimeout(function(){
						window.location.replace('LV.html');
					},2000);
					document.cookie = 'user=".$urse."';
					document.cookie = 'pas=".$pas."';
				</script>"; 
			}else{
				$wpsj[]="密码错误，请重新登录";
			}
		}
	}
	if($zhi=='zc'){
		$pass=$_GET["pass"];
		if($pas==$pass){
			if(mb_strlen($urse,"utf-8")<11&&mb_strlen($urse,"utf-8")>3){
				if(mb_strlen($pas,"utf-8")<11&&mb_strlen($pas,"utf-8")>3){
					$s="select * from urse where name='".$urse."';";
					$sql="insert into urse(name,pas) values('".$urse."','".$pas."');";
					if (mysqli_fetch_assoc(mysqli_query($link,$s))) {
						$wpsj[]="用户名已存在";
					}
					else{
						if (mysqli_query($link,$sql)) {
							$wpsj[]="注册成功,请前往登录";
						}else{
							$wpsj[]="注册失败";
						}
					}
				}else{
					$wpsj[]="密码不符合规则";
				}
			}else{
				$wpsj[]="用户名不符合规则";
			}
		}else{
			$wpsj[]="两次密码不一致";
		}
	}
	$jsonStr=json_encode($wpsj);
	echo $jsonStr;
?>
